package com.rfid.emergencywarehouse.manager;

import com.rfid.emergencywarehouse.entity.NameValueBean;

import java.util.ArrayList;
import java.util.List;

public enum FragmentDataManager {

    INSTANCE;

    List<NameValueBean> mData;
    List<Listener> mListeners = new ArrayList<>();

    NameValueBean mSelect;

    public List<NameValueBean> getData() {
        return mData;
    }


    public NameValueBean getSelect() {
        return mSelect;
    }

    public void addListener(Listener listener) {
        mListeners.add(listener);
    }

    public void removeListener(Listener listener) {
        mListeners.remove(listener);
    }

    public void setData(List<NameValueBean> beans) {
        mData = beans;
        if (beans == null) {
            return;
        }
        for (Listener listener : mListeners) {
            listener.onDatasChange(beans);
        }
    }

    public void select(NameValueBean bean) {
        mSelect = bean;
        if (bean == null) {
            return;
        }
        for (Listener listener : mListeners) {
            listener.onSelect(bean);
        }
    }
    public interface Listener{


        public default void onDatasChange(List<NameValueBean> beans){}

        public default void onSelect(NameValueBean v){}
    }


}
